package com.sxjh;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentPBEConfig;

/**
 * jasypt加解密工具类
 */
public class JasyptEncrypt {

    public static void main(String[] args) {
        StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
        EnvironmentPBEConfig config = new EnvironmentPBEConfig();
        config.setAlgorithm("PBEWithMD5AndDES");          // 加密的算法，这个算法是默认的
        config.setPassword("ys@top20220816");                        // 加密的密钥
        standardPBEStringEncryptor.setConfig(config);
        //加密
        String pass = "root"; //要进行加密的信息
        String encPass = standardPBEStringEncryptor.encrypt(pass);
        System.out.println("encPass:" + encPass); //输出加密后的密文
        //解密
        String str = "DXIeTyPUEAUmbctcexkZSA==";
        String decPass = standardPBEStringEncryptor.decrypt(str);
        System.out.println("decrypt:" + decPass);
    }
}
